package bb.lanxing.lib.devices.bici.cmd;

import com.umeng.analytics.pro.cc;
import bb.lanxing.lib.devices.bici.BLECommand;
import bb.lanxing.lib.devices.bici.BiciDate;
import java.io.Serializable;
import java.nio.ByteBuffer;
import java.util.Map;

public class StatusCMD extends BLECommand implements Serializable {
    public static final byte COMMAND_ID = 6;
    public static final byte KEY_ALARM = 6;
    public static final byte KEY_BATTERY = 7;
    public static final byte KEY_GPS = 2;
    public static final byte KEY_GPS_SIGN = 10;
    public static final byte KEY_GSM = 3;
    public static final byte KEY_LIGHT = 4;
    public static final byte KEY_LOCATION = 9;
    public static final byte KEY_LOCK = 8;
    public static final byte KEY_SOUND = 5;
    public static final byte KEY_STATUS = 1;
    public static final short LOCATION_LEN = 20;
    public static final byte STATE_ALL = 1;
    public static final byte STATE_LOCATION = 2;
    private byte alarm;
    private float alt;
    private byte battery;
    private long biciTime;
    private byte gps;
    private byte gpsSign;
    private byte gsm;
    private float lat;
    private byte[] light;
    private byte[] location;
    private byte lock;
    private float lon;
    private byte sound;
    private float speed;
    private byte status;
    private long timestamp;

    public StatusCMD() {
        this.commandId = (byte) 6;
    }

    public StatusCMD(byte[] bArr) {
        super(bArr);
    }

    @Override
    public void parseBody(byte[] bArr) {
        if (bArr.length < 3) {
            return;
        }
        ByteBuffer wrap = ByteBuffer.wrap(bArr);
        byte b = wrap.get();
        int i = wrap.getShort();
        byte[] bArr2 = new byte[(bArr.length - i) - 3];
        switch (b) {
            case 1:
                this.status = wrap.get();
                break;
            case 2:
                this.gps = wrap.get();
                break;
            case 3:
                this.gsm = wrap.get();
                break;
            case 4:
                byte[] bArr3 = new byte[i];
                this.light = bArr3;
                wrap.get(bArr3);
                break;
            case 5:
                this.sound = wrap.get();
                break;
            case 6:
                this.alarm = wrap.get();
                break;
            case 7:
                this.battery = wrap.get();
                break;
            case 8:
                this.lock = wrap.get();
                break;
            case 9:
                byte[] bArr4 = new byte[i];
                this.location = bArr4;
                wrap.get(bArr4);
                parseLocationDatas();
                break;
            case 10:
                this.gpsSign = wrap.get();
                break;
        }
        wrap.get(bArr2);
        parseBody(bArr2);
    }

    private void parseLocationDatas() {
        ByteBuffer wrap = ByteBuffer.wrap(this.location);
        this.lon = wrap.getInt();
        this.lat = wrap.getInt();
        this.alt = wrap.getInt();
        int i = wrap.getInt();
        this.biciTime = i & 4294967295L;
        this.timestamp = BiciDate.biciDateToTimestamp(i);
        this.speed = wrap.getInt();
    }

    public String toString() {
        return "status = " + ((int) this.status) + "\n gps = " + ((int) this.gps) + "\n gsm = " + ((int) this.gsm) + "\n sound = " + ((int) this.sound) + "\n alarm = " + ((int) this.alarm) + "\n battery = " + ((int) this.battery) + "\n lock = " + ((int) this.lock) + "\n lon = " + this.lon + "\n lat = " + this.lat + "\n alt = " + this.alt + "\n biciTime = " + this.biciTime + "\n timeStamp = " + this.timestamp + "\n timeString = " + BiciDate.getFormatDate(1, this.timestamp) + "\n speed = " + this.speed + "\n gpsSign = " + ((int) this.gpsSign);
    }

    @Override
    protected byte[] encodeCMDBody(Map<Byte, Object> map) {
        int i;
        ByteBuffer allocate = ByteBuffer.allocate(500);
        allocate.put((byte) 6);
        allocate.put((byte) 16);//cc.n
        if (map.get((byte) 1) != null) {
            allocate.put((byte) 1);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 1));
            i = 6;
        } else {
            i = 2;
        }
        if (map.get((byte) 2) != null) {
            allocate.put((byte) 2);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 2));
            i += 4;
        }
        if (map.get((byte) 3) != null) {
            allocate.put((byte) 3);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 3));
            i += 4;
        }
        if (map.get((byte) 4) != null) {
            allocate.put((byte) 4);
            byte[] bArr = (byte[]) map.get((byte) 4);
            allocate.putShort((short) bArr.length);
            allocate.put(bArr);
            i = i + 3 + bArr.length;
        }
        if (map.get((byte) 5) != null) {
            allocate.put((byte) 5);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 5));
            i += 4;
        }
        if (map.get((byte) 6) != null) {
            allocate.put((byte) 6);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 6));
            i += 4;
        }
        if (map.get((byte) 7) != null) {
            allocate.put((byte) 7);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 7));
            i += 4;
        }
        if (map.get((byte) 8) != null) {
            allocate.put((byte) 8);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 8));
            i += 4;
        }
        if (map.get((byte) 9) != null) {
            allocate.put((byte) 9);
            allocate.putShort((short) 20);
            allocate.put((byte[]) map.get((byte) 9));
            i = i + 3 + 20;
        }
        if (map.get((byte) 10) != null) {
            allocate.put((byte) 10);
            allocate.putShort((short) 1);
            allocate.put((Byte) map.get((byte) 10));
            i += 4;
        }
        byte[] bArr2 = new byte[i];
        allocate.flip();
        allocate.get(bArr2);
        return bArr2;
    }

    public byte getStatus() {
        return this.status;
    }

    public byte getGps() {
        return this.gps;
    }

    public byte getGsm() {
        return this.gsm;
    }

    public byte[] getLight() {
        return this.light;
    }

    public byte getSound() {
        return this.sound;
    }

    public byte getAlarm() {
        return this.alarm;
    }

    public byte getBattery() {
        return this.battery;
    }

    public byte getLock() {
        return this.lock;
    }

    public float getLon() {
        return this.lon;
    }

    public float getLat() {
        return this.lat;
    }

    public float getAlt() {
        return this.alt;
    }

    public long getTimestamp() {
        return this.timestamp;
    }

    public float getSpeed() {
        return this.speed;
    }

    public byte[] getLocation() {
        return this.location;
    }

    public byte getGpsSign() {
        return this.gpsSign;
    }

    public void setGpsSign(byte b) {
        this.gpsSign = b;
    }
}
